﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class ModifierExporteForm : Form
    {
        private Exportés Exp = new Exportés();

        public Exportés EXP
        {
            get { return Exp; }
            set { Exp = value; }
        }
        public ModifierExporteForm()
        {
            InitializeComponent();
            RAMEDEntities1 context = SingletonContext.GetContext();
            comboBoxdis.DataSource = context.Distinataires;
            comboBoxdis.DisplayMember = "Nom_Distinataire";
            comboBoxdis.ValueMember = "id_Distinataire";
            
        }
        public RechercherExportésFormcs Rechercheexpform { get; set; }

        private void btnajouter_Click(object sender, EventArgs e)
        {
            RAMEDEntities1 Context = SingletonContext.GetContext();
            Exportés Exp = new Exportés();
            Exp = Context.Exportés.Where(d => d.Id_message_exporté == EXP.Id_message_exporté).First();
            Exp.Num_message = utitlitaire.CasterString(txtnombre.Text);    
            Exp.Objet = txtobjet.Text;
            Exp.Date_envoi = dateTimePickerdateenv.Value;
            Exp.id_Distinataire = ((Distinataire)comboBoxdis.SelectedItem).id_Distinataire;
            Rechercheexpform.mettreAjourFormGridView();

            Context.SaveChanges();
            this.Dispose();
        }
        public void InitialiserChamps()
        {
            txtnombre.Text = Exp.Num_message.ToString();
            txtobjet.Text = Exp.Objet;
            dateTimePickerdateenv.Value = Exp.Date_envoi.Value;
            comboBoxdis.SelectedValue = Exp.Distinataire.id_Distinataire;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void Button21_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
        }

        private void modifierImages_Click(object sender, EventArgs e)
        {

            Imageviewerexportes imageviexerexp = new Imageviewerexportes();
            foreach (Image_Message_exporté imageiexp in Exp.Image_Message_exporté)
                imageviexerexp.images.Add(utitlitaire.ConvertirBinaryAImage(imageiexp.Image_));
            imageviexerexp.Show();
        }
    }
}
